using MediatR;
using B.S.XZYData.ErrorCode;
using System;
using System.Collections.Generic;

namespace B.S.XZYData.Api.Read.Application.Command.Approval
{
    /// <summary>
    /// 查询审批详情命令
    /// </summary>
    public class QueryApprovalDetailCommand : IRequest<ApiResult<ApprovalDetailResult>>
    {
        /// <summary>
        /// 流程实例ID
        /// </summary>
        public int WorkflowInstanceId { get; set; }
    }

    /// <summary>
    /// 审批详情结果
    /// </summary>
    public class ApprovalDetailResult
    {
        /// <summary>
        /// 基本信息
        /// </summary>
        public ApprovalDetailDto ApprovalInfo { get; set; } = new ApprovalDetailDto();

        /// <summary>
        /// 表单数据
        /// </summary>
        public WorkCompletionFormData? FormData { get; set; }

        /// <summary>
        /// 审批历史记录
        /// </summary>
        public List<ApprovalHistoryDto> ApprovalHistory { get; set; } = new List<ApprovalHistoryDto>();
    }

    /// <summary>
    /// 审批详情DTO
    /// </summary>
    public class ApprovalDetailDto
    {
        /// <summary>
        /// 流程实例ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 流程实例唯一标识
        /// </summary>
        public string WorkflowId { get; set; } = string.Empty;

        /// <summary>
        /// 工单编号
        /// </summary>
        public string WorkOrderCode { get; set; } = string.Empty;

        /// <summary>
        /// 唯一工单编号
        /// </summary>
        public string WorkOrderNo { get; set; } = string.Empty;

        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; } = string.Empty;

        /// <summary>
        /// 工序编码
        /// </summary>
        public string ProcessCode { get; set; } = string.Empty;

        /// <summary>
        /// 流程标题
        /// </summary>
        public string Title { get; set; } = string.Empty;

        /// <summary>
        /// 申请人
        /// </summary>
        public string ApplicantUserName { get; set; } = string.Empty;

        /// <summary>
        /// 当前审批步骤
        /// </summary>
        public string? StepName { get; set; }

        /// <summary>
        /// 当前审批人
        /// </summary>
        public string? AuditUserName { get; set; }

        /// <summary>
        /// 流程状态
        /// </summary>
        public string Status { get; set; } = string.Empty;

        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime? CompletedTime { get; set; }
    }

    /// <summary>
    /// 完工表单数据
    /// </summary>
    public class WorkCompletionFormData
    {
        /// <summary>
        /// 报工记录ID
        /// </summary>
        public int WorkReportId { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string WorkOrderCode { get; set; } = string.Empty;

        /// <summary>
        /// 唯一工单编号
        /// </summary>
        public string WorkOrderNo { get; set; } = string.Empty;

        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; } = string.Empty;

        /// <summary>
        /// 工序编码
        /// </summary>
        public string ProcessCode { get; set; } = string.Empty;

        /// <summary>
        /// 产品编码
        /// </summary>
        public string ProductCode { get; set; } = string.Empty;

        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName { get; set; } = string.Empty;

        /// <summary>
        /// 报工数量
        /// </summary>
        public int ReportQty { get; set; }

        /// <summary>
        /// 良品数量
        /// </summary>
        public int GoodQty { get; set; }

        /// <summary>
        /// 不良品数量
        /// </summary>
        public int BadQty { get; set; }

        /// <summary>
        /// 不良原因
        /// </summary>
        public string? DefectReason { get; set; }

        /// <summary>
        /// 生产人员
        /// </summary>
        public string Producer { get; set; } = string.Empty;

        /// <summary>
        /// 工作时长（小时）
        /// </summary>
        public decimal WorkHours { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 完工时间
        /// </summary>
        public DateTime CompletionTime { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }
    }

    /// <summary>
    /// 审批历史记录DTO
    /// </summary>
    public class ApprovalHistoryDto
    {
        /// <summary>
        /// 审批记录ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 流程实例ID
        /// </summary>
        public int WorkflowInstanceId { get; set; }

        /// <summary>
        /// 审批步骤
        /// </summary>
        public string StepName { get; set; } = string.Empty;

        /// <summary>
        /// 审批人
        /// </summary>
        public string AuditUserName { get; set; } = string.Empty;

        /// <summary>
        /// 操作类型（通过、驳回）
        /// </summary>
        public string OperationType { get; set; } = string.Empty;

        /// <summary>
        /// 审批意见
        /// </summary>
        public string? Comment { get; set; }

        /// <summary>
        /// 审批时间
        /// </summary>
        public DateTime AuditTime { get; set; }
    }
} 